package ch.soreco.standard.xexpenses.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.io.IOUtils;

public class FileConverter {
	
	public static byte[] convertToImgFormat(File input) throws Exception{
		FileInputStream is = new FileInputStream(ThumbnailManager.createThumbnail(input).getFile());
		return IOUtils.toByteArray(is);
	}
	
	public static byte[] getContent(File input) throws IOException{
		FileInputStream is = new FileInputStream(input);
		return IOUtils.toByteArray(is);
	}
	
	public static boolean isImageFile(File input){
		try {
		    if (ImageIO.read(input) == null) {
		        return false;
		    }
		} catch(IOException ex) {
			 return false;
		}
		
		return true;
	}

}
